#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
static unsigned char send_buf[10]="1234567";
static unsigned char recv_buf[10];
#define MAX_LEN 100
static int fd;
static void pabort(const char *s)
{
  perror(s);
  abort();
}
void input_handler(int num)
{
  char data[MAX_LEN];
  int len; 
  len = read(fd, &data, MAX_LEN);
  data[len] = 0;
  printf("input available:%s !!!!!!!!!!!!!!\n", data);
}
main()
{
  char data[MAX_LEN];
  int oflags;
  fd = open("/dev/irq_hz512", O_RDWR);
  if(fd < 0)
    return;
  printf("fd open\n");
  signal(SIGIO, input_handler);
  fcntl(fd, F_SETOWN, getpid());
  oflags = fcntl(fd, F_GETFL);
  fcntl(fd, F_SETFL, oflags | FASYNC);
  sleep(2);
  write(fd, &data, 1);
  printf("write to fd\n");
  while (1)
  {
    sleep(4);
  printf("waiting....\n");
  }
}

// int main(){
//   int fd;
//   int num = 5;
//   int i=0;
//   /* open the pneumatic DSP bin code file. */
//   fd = open("/dev/spi_dev", O_RDWR);
//   if (fd < 0)
//     pabort("can't open SPI device");
//   write(fd,send_buf,num);
//   read(fd,recv_buf,num);
//   for(i=0;i<num;i++)
//     printf("recv_buf[%d]:%d\n",i,recv_buf[i]);
//   close(fd);
//  return 0;
// }

